Setting up NGINX
This tutorial will guide you through the steps to reverse proxy from the Webserver VM to another VM.
For all steps replace ABAIR_APP_SUBDOMAIN with the subdomain you will configure in Cloudflare DNS.
Prerequisites:
- Sudo access to the ABAIR Webserver VM. (See Server List)
Creating an NGINX config file for Your Project
1. Sign into to the Webserver VM as a sudo user
ssh USERNAME@srv.abair.ie -p 22102
2. Navigate to the NGINX sites directory /etc/nginx/sites-available/
cd /etc/nginx/sites-available/
3. Create/edit your projects file with the following command
sudo nano ABAIR_APP_SUBDOMAIN.abair.ie
4. Copy the following into this file, replacing
YOUR_PORT_HEREwith the port your app is served on.YOUR_VM_ADDRESS_HEREwith the local VM address your app is running on. (ie. services is10.0.0.2)ABAIR_APP_SUBDOMAINwith the same subdomain name as before.
server {
listen 80;
server_name ABAIR_APP_SUBDOMAIN.abair.ie;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name ABAIR_APP_SUBDOMAIN.abair.ie;
ssl_certificate /etc/letsencrypt/live/abair.ie/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/abair.ie/privkey.pem; # managed by Certbot
access_log /etc/nginx/log/access_ABAIR_APP_SUBDOMAIN.abair.ie;
error_log /etc/nginx/log/error_ABAIR_APP_SUBDOMAIN.abair.ie;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://YOUR_VM_ADDRESS_HERE:YOUR_PORT_HERE;
}
}
5. Create a symlink to your newly created config file
sudo ln -s /etc/nginx/sites-available/ABAIR_APP_SUBDOMAIN.abair.ie /etc/nginx/sites-enabled/ABAIR_APP_SUBDOMAIN.abair.ie
6. Check the NGINX config files are set up ok
sudo nginx -t
You should see:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
7. Reload NGINX
sudo systemctl reload nginx
8. Check your site is runnung at ABAIR_APP_SUBDOMAIN.abair.ie
If you configured Cloudflare DNS for your project and ran it on the port which you enabled, then you should see it at ABAIR_APP_SUBDOMAIN.abair.ie.